package com.example.cinemasystemv2.repository;

import com.example.cinemasystemv2.entity.Snack;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface SnackRepository extends JpaRepository<Snack, Long> {
    
    Optional<Snack> findByName(String name);
    
    @Query("SELECT s FROM Snack s WHERE s.stock > 0")
    List<Snack> findAvailableSnacks();
    
    @Query("SELECT s FROM Snack s WHERE s.stock <= :threshold")
    List<Snack> findLowStockSnacks(@Param("threshold") int threshold);
    
    @Query("SELECT s FROM Snack s WHERE s.name LIKE %:keyword%")
    List<Snack> searchSnacks(@Param("keyword") String keyword);
    
    boolean existsByName(String name);
    
    @Query("SELECT COUNT(s) FROM Snack s WHERE s.stock > 0")
    long countAvailableSnacks();
}